home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.08 Aug 89 / POOPDraw Code ƒ / !POOP Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-12  |  3.5 KB  |  137 lines  |  [TEXT/KAHL]

  1. /********************************************************************/
  2. /*                                                                    */
  3. /*                        THE POOP SHELL                                */
  4. /*                                                                    */
  5. /********************************************************************/
  6. /*        An Adventure in Pseudo-Object-Oriented-Programming            */
  7. /********************************************************************/
  8. /*
  9. *   >>>    File name:        Main
  10. *
  11. *      >>>    Purpose:        The main, start-up and shutdown routines
  12. *     >>>    Project:        PoopDraw        
  13. *     >>>    Date:            June 5, 1989
  14. *      >>>    By:                Adam Treister
  15. *
  16. */
  17. /********************************************************************/
  18. /*    For Your Information            1802 Hillside Rd. SB CA 93101    */
  19. /********************************************************************/
  20.  
  21. #include "PoopDrawInc"
  22.  
  23. /********************************************************************/
  24.  
  25.                 main            (void);
  26. private void     WakeUp            (void);
  27. private void     Die                (void);
  28.  
  29. foreign void     Twiddle    (void);
  30. foreign void     ApplicationInit    (void);
  31. foreign void     ApplicationShutDown    (void);
  32.  
  33.  
  34. /********************************************************************/
  35. /*                        THE GLOBAL DECLARATIONS                        */
  36. /********************************************************************/
  37.  
  38. MenuHandle        Menus[NUMMENUS];
  39. EventRecord     Event;                        /* the Event Record */
  40. long            LastMouseDown = 0;            /* time of last mouse down  */
  41. Boolean            MillerTime = false;            /* Quit flag */
  42. int                errno;
  43.  
  44. /* ------------------------------------------------------------ */
  45. /*                                                                */
  46. /*                            MAIN                                */
  47. /*                                                                */
  48. /*        The standard shit - init, run, shutdown                    */
  49. /*                                                                */
  50. /* ------------------------------------------------------------ */
  51.  
  52. main()
  53. {
  54.     WakeUp();
  55.     Twiddle();
  56.     Die();
  57. }
  58.  
  59. /* ------------------------------------------------------------ */
  60. /*                                                                */
  61. /*                        WAKE UP                                    */
  62. /*                                                                */
  63. /*    This function  initialises the Mac Toolbox, creates the        */
  64. /*    menu bar and calls an application specific init routine     */
  65. /*                                                                */
  66. /* ------------------------------------------------------------ */
  67.  
  68.  
  69. void WakeUp()
  70. {
  71.             WindowPtr    win;
  72.             register     int                i;
  73.             extern        MenuHandle        Menus[];
  74.     
  75.     InitMacintosh();
  76.       TurnWatchOn();
  77.  
  78.     for (i=0; i < NUMMENUS; i++ ) 
  79.     {
  80.         Menus[i] = GetMenu(i + AppleMenuID-1);
  81.         InsertMenu(Menus[i], 0);
  82.     }
  83.     AddResMenu(Menus[0],'DRVR');
  84.     DrawMenuBar();
  85.     HiliteMenu(0);
  86.  
  87.      ApplicationInit();
  88.     TurnArrowOn();
  89. }
  90.  
  91. /* ------------------------------------------------------------ */
  92. /*                                                                */
  93. /*                    DIE                                            */
  94. /*                                                                */
  95. /*    Tidys up everything before the application quits.            */
  96. /*    If there any windows open they are closed.                     */
  97. /*                                                                */
  98. /* ------------------------------------------------------------ */
  99.  
  100. void Die()
  101. {
  102.  
  103.     Str255 message,ctStr,sizStr;
  104.     
  105.  
  106.      while (MyFrontWindow())
  107.     {
  108.         WDispatch(MyFrontWindow(),CLOSE,NULL);
  109.     }    
  110.     ApplicationShutDown();
  111.     ExitToShell();
  112. }
  113. /*------------------------------------------------------------------*/
  114. /*    send messages to the appropriate object
  115. /*------------------------------------------------------------------*/
  116. void  Dispatch(ObjectH,Message,ParmP)
  117. ObjectHandle ObjectH;
  118. int Message;
  119. LPtr ParmP;
  120.     if (ObjectH)    
  121.         (*(*ObjectH)->dispatch)(ObjectH,Message,ParmP); 
  122. }
  123. /*------------------------------------------------------------------*/
  124. /*    A special case of Dispatch exclusively for windows. 
  125. /*------------------------------------------------------------------*/
  126.  
  127. void  WDispatch(wP,Message,ParmP)
  128. WindowPtr wP;
  129. int Message;
  130. LPtr ParmP;
  131.     ObjectHandle obj;
  132.     obj = (ObjectHandle) GetWRefCon(wP);
  133.     if (obj)    (*(*obj)->dispatch)(obj,Message,ParmP);
  134. }
  135.